﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        read();
    }


    private void read()
    {
      

        using (DataClassesDataContext db = new DataClassesDataContext())
        {
            Users user = db.Users.SingleOrDefault(p => p.email == txtUser.Text && p.password == txtPassword.Text );
            Session["user"] = user;
            if (user != null)
            {

                if (user.admin)
                {
                    Response.Redirect("admin/Users.aspx");
                }
                else Response.Redirect("admin/Payments.aspx");

            }
            else
            {
                messagesDB.displayMessage("Email o password incorrecto.", messagesDB.MessageTypes.ErrorMessage, this);
            }

          

        }
    }
}